#include "mypushbutton.h"

MyPushButton::MyPushButton(QWidget *parent) : QPushButton(parent)
{

}

MyPushButton::MyPushButton(QString normal, QString push){
    QPixmap pixmap;

    this->normal = normal;
    this->push = push;

    bool result = pixmap.load(this->normal);
    if(!result){
        qDebug()<<"image load error";
        return;
    }
    this->setIcon(QIcon(pixmap));
    this->setIconSize(QSize(this->height(), this->width()));
    this->resize(pixmap.width(), pixmap.height());
    qDebug()<<pixmap.height();
    qDebug()<<pixmap.width();
    this->setStyleSheet("QPushButton{border: 0px}");

}

void MyPushButton::zoomUp(){
    QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
    animation->setDuration(200);

    animation->setStartValue(QRect(this->x(), this->y(), this->width(), this->height()));
    animation->setEndValue(QRect(this->x(), this->y() + 10, this->width(), this->height()));
    animation->start();
}

void MyPushButton::zoomDown(){
    QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
    animation->setDuration(200);

    animation->setStartValue(QRect(this->x(), this->y() - 10, this->width(), this->height()));
    animation->setEndValue(QRect(this->x(), this->y(), this->width(), this->height()));
    animation->start();
}

void MyPushButton::mousePressEvent(QMouseEvent* event) {
    if(this->push != ""){
        QPixmap pixmap;
        bool res = pixmap.load(this->push);
        if(!res){
            qDebug() << "image load error";
            return;
        }
        this->setIcon(QIcon(pixmap));
        this->setIconSize(QSize(this->width(), this->height()));
        this->resize(pixmap.width(), pixmap.height());
        this->setStyleSheet("QPushButton{border: 0px}");

    }

    QPushButton::mousePressEvent(event);

}

void MyPushButton::mouseReleaseEvent(QMouseEvent* event) {
    if(this->normal != ""){
        QPixmap pixmap;
        bool res = pixmap.load(this->normal);
        if(!res){
            qDebug() << "image load error";
            return;
        }
        this->setIcon(QIcon(pixmap));
        this->setIconSize(QSize(this->width(), this->height()));
        this->resize(pixmap.width(), pixmap.height());
        this->setStyleSheet("QPushButton{border: 0px}");

    }
    QPushButton::mouseReleaseEvent(event);


}
